package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.vo.StoreProductVo;
import com.ruoyi.fly.mapper.StoreProductMapper;
import com.ruoyi.fly.service.StoreProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StoreProductServiceImpl implements StoreProductService {

    @Autowired
    private StoreProductMapper storeProductMapper;

    /**
     * 新增店铺商品
     * @param storeProductVo
     * @return
     */
    @Override
    public R insertStoreProduct(StoreProductVo storeProductVo) {
        storeProductVo.setCreateTime(DateUtils.getNowDate());
        storeProductVo.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return storeProductMapper.insertStoreProduct(storeProductVo) > 0 ? R.ok("新增成功") : R.fail("操作失败");
    }

    /**
     * 修改店铺商品
     * @param storeProductVo
     * @return
     */
    @Override
    public R updateStoreProduct(StoreProductVo storeProductVo) {
        storeProductVo.setUpdateTime(DateUtils.getNowDate());
        storeProductVo.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return storeProductMapper.updateStoreProduct(storeProductVo) > 0 ? R.ok("修改成功") : R.fail("操作失败");
    }

    /**
     * 删除店铺商品
     * @param id
     * @return
     */
    @Override
    public R deleteStoreProductById(String id) {
        return storeProductMapper.deleteStoreProductById(id) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }

    @Override
    public R deleteStoreProductByIds(String[] id) {
        return storeProductMapper.deleteStoreProductByIds(id) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }
}
